package cn.hs.service.impl;

import cn.hs.entity.Question;
import cn.hs.entity.User;
import cn.hs.mapper.QuestionMapper;
import cn.hs.mapper.UserMapper;
import cn.hs.service.QuestionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName QuestionServiceImpl
 * @Description TODO
 * @Author wsh
 * @Date 2024年10月24日 16:59
 * @Version 1.0
 */
@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionMapper questionMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo findAll(Integer pageNum, Integer pageSize, Question question) {
        //分页业务的实现
        PageHelper.startPage(pageNum,pageSize);
        List<Question> questions=questionMapper.select(question);
//        for(int i=0;i<questions.size();i++){
//            User user=userMapper.selectById(questions.get(i).getUserId());
//
//        }
        PageInfo<Question> pageInfo=new PageInfo<>(questions);
        return pageInfo;
    }

    @Override
    public List<Question> find(Question question) {
        return questionMapper.select(question);
    }

    @Override
    public int insert(Question question) {
        return questionMapper.insert(question);
    }

    @Override
    public int update(Question question) {
        return questionMapper.update(question);
    }

    @Override
    public int delete(Integer id) {
        return questionMapper.delete(id);
    }
}
